package com.colt.contentcenter.controller.place;

import cn.hutool.core.lang.UUID;
import com.alibaba.fastjson.JSON;
import com.colt.contentcenter.domain.entity.city.City;
import com.colt.contentcenter.service.place.PlaceService;
import com.colt.contentcenter.util.response.BaseResponse;
import com.colt.contentcenter.util.response.CodeEnum;
import com.colt.contentcenter.util.response.ResponseData;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedList;
import java.util.List;

/**
 * @program: spring-cloud-alibaba-we-chat-app
 * @description: 获取地名controller
 * @author: colt
 * @create: 2020-12-07 09:53
 **/
@RestController
@RequestMapping("/place")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PlaceController {
    private final PlaceService placeService;
    @GetMapping("/getAll")
    public BaseResponse getAllPlace(@RequestParam(required = false) String cityName){
        List<City> cities = this.placeService.placeAll(cityName);
        if (CollectionUtils.isEmpty(cities)){
            BaseResponse out = BaseResponse.out(CodeEnum.FAIL);
            out.setMsg("未查询到数据~");
            return out;
        }else {
            BaseResponse out = ResponseData.out(CodeEnum.SUCCESS,cities);
            out.setMsg("查询成功~");
            return out;
        }

    }
    public static void main(String[] args) {
        BaseResponse out = BaseResponse.out(CodeEnum.SUCCESS);
        System.out.println("基本响应封装:\n" + JSON.toJSONString(out));
        List<String> list = new LinkedList<>();
        list.add(UUID.randomUUID().toString());
        ResponseData<List<String>> data = ResponseData.out(CodeEnum.FAIL, list);
        System.out.println("响应数据结构封装:\n" + JSON.toJSONString(data));
    }
}
